package com.samsung.spen.sshare.main.data;


import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;

public class DataHelper extends SQLiteOpenHelper implements HistoryColumns, RequestSMSColumns, CommunicationLogColumns{
	
	private static final String DATABASE_NAME = "sshare.db";
	private static final int DATABASE_VERSION = 2;
	
	
	public DataHelper(Context context){
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE " + HISTORY_TABLE_NAME + " ("
				+ HistoryColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
				+ HistoryColumns.PHONE_NUMBER + " VARCHAR(20),"
				+ HistoryColumns.IP + " VARCHAR(20),"
				+ FILE_NAME + " VARCHAR(50),"
				+ FILE_PATH + " VARCHAR(500),"
				+ SIZE + " INTEGER,"
				+ HistoryColumns.DATE_TIME + " INTEGER,"
				+ STATUS + " INTEGER" + ");");
		db.execSQL("CREATE TABLE " + REQUEST_SMS_TABLE_NAME + " ("
				+ RequestSMSColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
				+ RequestSMSColumns.PHONE_NUMBER + " VARCHAR(20),"
				+ RequestSMSColumns.DATE_TIME + " INTEGER,"
				+ CONTENT + " VARCHAR(1000),"
				+ RequestSMSColumns.IP + " VARCHAR(20)," 
				+ SMS_STATUS + " INTEGER DEFAULT 0" +");");
		db.execSQL("CREATE TABLE " + COMMUNICATION_LOG_TABLE_NAME + " ("
				+ CommunicationLogColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
				+ CommunicationLogColumns.PHONE_NUMBER + " VARCHAR(20),"
				+ CommunicationLogColumns.LAST_COMMUNICATION_TIME + " INTEGER" +");");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + HISTORY_TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + REQUEST_SMS_TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + COMMUNICATION_LOG_TABLE_NAME);
		onCreate(db);
	}
}
